/*=========================================================================

Program:   Virtual Surgery
Language:  C++
Date:      2009-9-1
Version:   0.1
Mail:		   nelfylee@gmail.com

Copyright (c) 2009 Nelfy Lee. All rights reserved.

=========================================================================*/
#ifndef _SOURCE_H_
#define _SOURCE_H_

#include "vtkImageData.h"
#include "vtkImageMarchingCubes.h"
#include "vtkPolyDataMapper.h"
#include "vtkActor.h"
#include "vtkVolume.h"
#include "vtkImageCast.h"
#include "vtkPiecewiseFunction.h"
#include "vtkColorTransferFunction.h"
#include "vtkVolumeProperty.h"
#include "vtkVolumeRayCastCompositeFunction.h"
#include "vtkVolumeRayCastMapper.h"
#include "vtkVolume.h"
#include "vtkOutlineFilter.h"
#include "vtkContourFilter.h"
#include "vtkPolyDataNormals.h"
#include "vtkStripper.h"

#include <QWidget>
#include <math.h>
#include <QMetaType>
#include <QStandardItem>
#include <QColor>
#include <QList>
#include <QDebug>


class PipelineModel;

enum SourceType
{ 
	stNone = 0,
	stVolume = 1,			// 0
	stBinaryVolume,		// 1
	stImage,			// 2
	stSurface			// 3
};


enum SourceProperty
{
	spDisplayOutline = 1,
	spDisplaySurface,
	spDisplayVolume,
	spWindowLevel,
	spVisibility,
	spThreshold,
	spBlending,
	spSurfaceOpacity,
	spPositionChanged,
	spRebuildSurface
};


/************************************************************************/
/*                                                                      */
/************************************************************************/


class Source : public QStandardItem
{
public:
	Source(const QString &text);
	~Source();
	
	virtual void addChild(Source *source);

	virtual int dim();		// 2 or 3
	virtual SourceType type();
	virtual int dataType();

	virtual QString fileName();
	virtual void setFileName(QString fileName);	

	virtual vtkImageData* data();
	virtual vtkProp* sourceModel(bool refresh=false) = 0;
	virtual void clearModel();
	//virtual bool isModeling();

	virtual vtkActor* outlineActor();
	virtual void clearOutlineActor();
	
	virtual QStringList childrenList();

public:
	QList<QColor> *g_colorTable;

protected:
	friend class PipelineModel;

	void emitPropertyChanged(SourceProperty);
	void initModelParameters();

protected:
	QString m_sourceText;			// the name displaying in the Tree view
	QString m_fileName;				// for 2D it is filename, for 3D it is the first filename

	int m_dataType;
	SourceType m_type;		// basic source type
	PipelineModel *m_pipelineModel;

	vtkImageData *m_vtkImage;		// the vtkImageData
	//vtkProp *m_sourceModel;

	// outline
	vtkActor *m_outlineActor;
	vtkPolyDataMapper *m_outlinePolyDataMapper;
	vtkOutlineFilter *m_outlineFilter;
};



#endif



